package testLayer;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import controlLayer.TeacherCtr;

public class TeacherControllerTest {
	
	private TeacherCtr teacherCtr;
	
	@Before
	public void setUp() throws Exception {
		
		this.teacherCtr = new TeacherCtr();
		this.insert();
		
	}
	
	@After
	public void tearDown() throws Exception {
		
		this.remove();
		this.teacherCtr = null;
			
	}
	
	public void insert() throws Exception {
		
		assertTrue(this.teacherCtr.createTeacher("Ole Test", "120489-5677", "Hobrovej 12", 
												 "98121212", "ole@omail.dk", 12) > 0);
	 
	}
	
	@Test
	public void find() throws Exception {
		
		assertNotNull(this.teacherCtr.findTeacher("Ole Test").get(0));

	}
	
	@Test
	public void findById() throws Exception {
	
		assertNotNull(this.teacherCtr.findTeacherById(this.teacherCtr.findTeacher("Ole Test").get(0).getId()));

	}
	
	@Test
	public void getAll() throws Exception {
		
		assertTrue(!this.teacherCtr.getAll().isEmpty() && 1 <= this.teacherCtr.getAll().size());

	}
	
	@Test
	public void update() throws Exception {
		
		assertTrue(this.teacherCtr.updateTeacher(this.teacherCtr.findTeacher("Ole Test").get(0)) > 0);
		
	}

	public void remove() throws Exception {
		
		assertTrue(this.teacherCtr.removeTeacher(this.teacherCtr.findTeacher("Ole Test").get(0).getId()) > 0);
		
	} 

}
